GCP K8s Quickstart

GCP K8s Quickstart

1. 安裝 gcloud

GCP Container Registry image安裝
Cloud SDK(Linux)快速入門

2. Creating a GKE cluster

1
./gcloud/google-cloud-sdk/bin/gcloud container clusters create [CLUSTER_NAME]

3. 安裝 kubectl

1
./gcloud/google-cloud-sdk/bin/gcloud components install kubectl

4. kubectl run Container Registry

4.1 Build Docker image

.net core webapi 建立可以參考這篇.net core webapi

1
docker build -t gcr.io/[your-projectid]/netcorewebapi:v1

4.2 Push image to GCR

1
docker push gcr.io/[your-projectid]/netcorewebapi:v1

4.3 執行服務

1
kubectl run netcorewebapi --image gcr.io/[your-projectid]/netcorewebapi:v1 --port 80

4.4. 公開 k8s 容器

1
kubectl expose deployment netcorewebapi  --type LoadBalancer --port 80 --target-port 80

4.5. 取得服務的資訊

1
kubectl get service netcorewebapi

4.6 預覽

參考